import { axiosMock, delayFn, randArrItem } from '@/services/axiosMock'
import { IFiled } from '../interface'

axiosMock('default', mock => {
  // 获取运单动态字段
  mock.onPost(`/tmsapi/waybill_field/listWaybillField`).reply(
    delayFn(600, () => {
      return {
        success: true,
        data: [
          { attrKey: '运单ID', attrValue: '', type: 'dynamic_field' },
          ...Array(randArrItem([11]))
            .fill(null)
            .map<IFiled>((_, i) => ({
              attrKey: randArrItem([`字段${i + 1}`, `字段字段字段${i + 1}`]),
              attrValue: randArrItem([`字段值${i + 1}`, `字段值字段值字段值${i + 1}`]),
              type: randArrItem(['dynamic_field', 'address', 'date']),
            })),
        ],
      }
    }),
  )

  // 保存运单动态字段
  mock.onPost(`/tmsapi/waybill_field/saveWaybillField`).reply(
    delayFn(600, () => {
      return {
        success: true,
      }
    }),
  )
})
